/***************************************************************************
  pldp.cpp
  
  -------------------
         begin                : [PluginDate]
         copyright            : [(C) Your Name and Date]
         email                : [Your Email]

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
/*  $Id: plugin.cpp 9327 2008-09-14 11:18:44Z jef $ */

//
// QGIS Specific includes
//

#include <qgisinterface.h>
#include <qgisgui.h>

#include "pldp.h"
//
// Qt4 Related Includes
//

#include <QAction>
#include <QToolBar>
#include <QLibrary>
#include <QMessageBox>

#include "pipelineform.h"
#include "profileview.h"
#include "treemodel.h"
#include "unique.h"

static const char * const sIdent = "$Id: plugin.cpp 9327 2008-09-14 11:18:44Z jef $";
static const QString sName = QObject::tr( "&Электронный паспорт трубопровода" );
static const QString sDescription = QObject::tr( "" );
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;

//////////////////////////////////////////////////////////////////////
//
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
//
//////////////////////////////////////////////////////////////////////

/**
 * Constructor for the plugin. The plugin is passed a pointer
 * an interface object that provides access to exposed functions in QGIS.
 * @param theQGisInterface - Pointer to the QGIS interface object
 */
pldp::pldp( QgisInterface * theQgisInterface ):
    QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
    mQGisIface( theQgisInterface )
{
    unique::inst()->setQgisIface(theQgisInterface);
}

pldp::~pldp()
{    

}

/*
 * Initialize the GUI interface for the plugin - this is only called once when the plugin is
 * added to the plugin registry in the QGIS application.
 */
void pldp::initGui()
{    
//    //Устанавливаем кодировку выводимого текста в UTF8
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForCStrings(codec);

    mToolBar = mQGisIface->addToolBar("Трубопроводные системы");
    mToolBar->setObjectName("pldptoolbar");
    mToolBar->addAction("tmp", this, SLOT(debuginfo()) );

    //дерево
    pipeLineHierarhy = new HierarchyView();
    mQGisIface->addDockWidget(Qt::LeftDockWidgetArea, pipeLineHierarhy);

    //профиль
    profile = new ProfileView();
    mQGisIface->addDockWidget(Qt::BottomDockWidgetArea, profile);

}

// Unload the plugin by cleaning up the GUI
void pldp::unload()
{
    mQGisIface->removeDockWidget(pipeLineHierarhy);
    mQGisIface->removeDockWidget(profile);
    mToolBar->clear();
    delete mToolBar;
  // remove the GUI
  //mQGisIface->removePluginMenu( "&GeoMaster", mQActionPointer );
  //mQGisIface->removeToolBarIcon( mQActionPointer );

  //delete mQActionPointer;
}

void pldp::debuginfo()
{
    PipeLineForm *pplform = new PipeLineForm();
    pplform->loadData("98f2ab1d-3fc6-414e-ab67-e706e4820ada");
    pplform->show();
}

/**
 * Required extern functions needed  for every plugin
 * These functions can be called prior to creating an instance
 * of the plugin class
 */
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
{
  return new pldp( theQgisInterfacePointer );
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
  return sName;
}

// Return the description
QGISEXTERN QString description()
{
  return sDescription;
}

// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
  return sPluginType;
}

// Return the version number for the plugin
QGISEXTERN QString version()
{
  return sPluginVersion;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
  delete thePluginPointer;
}
